package top.zywork.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.zywork.common.BeanUtils;
import top.zywork.dao.GoodsCommissionDAO;
import top.zywork.dos.GoodsCommissionDO;
import top.zywork.dto.GoodsCommissionDTO;
import top.zywork.service.AbstractBaseService;
import top.zywork.service.GoodsCommissionService;

import javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.util.List;

/**
 * GoodsCommissionServiceImpl服务接口实现类<br/>
 *
 * 创建于2019-07-22<br/>
 *
 * @author http://zywork.top 王振宇
 * @version 1.0
 */
@Service(value = "goodsCommissionService")
public class GoodsCommissionServiceImpl extends AbstractBaseService implements GoodsCommissionService {

    private GoodsCommissionDAO goodsCommissionDAO;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int removeAndSaveBatch(Long goodsId, Long goodsSkuId, List<Object> dataTransferObjList) {
        goodsCommissionDAO.removeAllByGoods(goodsId, goodsSkuId);
        return goodsCommissionDAO.saveBatch(BeanUtils.copyList(dataTransferObjList, GoodsCommissionDO.class));
    }

    @Override
    public BigDecimal getCommissionPercent(Long userId, Long goodsId, Long goodsSkuId, Integer distributionLevel) {
        return goodsCommissionDAO.getCommissionPercent(userId, goodsId, goodsSkuId, distributionLevel);
    }

    @Autowired
    public void setGoodsCommissionDAO(GoodsCommissionDAO goodsCommissionDAO) {
        super.setBaseDAO(goodsCommissionDAO);
        this.goodsCommissionDAO = goodsCommissionDAO;
    }

    @PostConstruct
    public void init() {
        super.init(GoodsCommissionDO.class, GoodsCommissionDTO.class);
    }
}
